﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SGCG.Model;

namespace SGCG.Actions
{
    public class CreateArcAction : BorderedObjectCreationAction<Arc>
    {

        public CreateArcAction(PellBitmap pellBitmap) : base(pellBitmap) { }

        protected override Arc CreateObject(int x, int y)
        {
            return new Arc(null)
            {
                X = x,
                Y = y,
                Radius = 0,
                InitAngle = 0,
                ArcAngle = 0,
                LineStyle = LineStyle.Normal,
                LineThickness = LineThickness.Normal,
                Color = Colors.Black
            };
        }

        protected override void SetPointCore(int point, int x, int y)
        {
            if (point == 2)
            {
                this.BorderedObject.Radius = (int)Math.Round(Math.Sqrt((x - this.BorderedObject.X) * (x - this.BorderedObject.X) + (y - this.BorderedObject.Y) * (y - this.BorderedObject.Y)));
                this.BorderedObject.InitAngle = Math.Atan2(y - BorderedObject.Y, x - BorderedObject.X);
            }
            else if (point == 3)
            {
                this.BorderedObject.ArcAngle = ((Math.Atan2(y - BorderedObject.Y, x - BorderedObject.X) - BorderedObject.InitAngle) % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
            }
        }

        protected override bool HasMorePoints()
        {
            return this.CurrentPoint < 3;
        }

    }
}
